package com.sky.controller.user;

import com.sky.constant.RedisConstant;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.service.user.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户端查看营业状态
 */
@Slf4j
@Api(tags = "用户端营业状态")
@RestController("userShowController")
@RequestMapping("/user/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantService merchantService;

    @GetMapping("/status")
    @ApiOperation("用户获取店铺状态")
    public Result<Integer> userGetShowStatus() {
        Integer status = (Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        log.info("用户获取店铺状态:{}", status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }

    //  获取店铺电话
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result getMerchantInfo() {
        //  获取唯一商家对象信息
        Merchant merchant = merchantService.getShopById(1L);
        String shopName = merchant.getShopName();
        String shopAddress = merchant.getShopAddress();
        String shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return Result.success(build);
    }
}
